<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>后台管理模板</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="../../css/global.css" media="all">
		<link rel="stylesheet" type="text/css" href="http://www.jq22.com/jquery/font-awesome.4.6.0.css">
		<link rel="stylesheet" href="../../datatables/media/css/jquery.dataTables.css">
		<link rel="stylesheet" href="../../datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css">
	</head>
	<body>
		<div class="layui-layout layui-layout-admin" style="border-bottom: solid 5px #1aa094;">
			<!--头部导航-->
			<div class="layui-header header header-demo" ></div>
			<!--左侧导航-->
			<div class="layui-side layui-bg-black" id="admin-side">
			</div>
			<!--右侧具体内容-->
			<div class="layui-body" style="bottom: 0;border-left: solid 2px #1AA094;padding:20px" id="admin-body">
				<div><div class="title">快递员账号管理</div><button class="layui-btn layui-btn-small" style="float: right;margin:0 10px 10px 0">实时位置</button><button class="layui-btn layui-btn-small" style="float: right;margin:0 10px 10px 0">账号列表</button></div>
				<hr />
				<div class="select" >
					<select name="expreselect" lay-verify="" id="expressSequence">
						<option value="1">按编号↑</option>
						<option value="2">按总接单数↑</option>
						<option value="3">按总接单数↓</option>
						<option value="4">按创建时间↑</option>
						<option value="5">按创建时间↓</option>
						<option value="6">按评分↑</option>
						<option value="7">按评分↓</option>
					</select>
				</div>
				<div class="layui-form">
					<table class="layui-table" id="expressTable">
						<thead>
							<tr>
								<th><input type="checkbox" name="expresscheck" id="checkall" onchange="checkAll(this,'#expressTable')"></th>
								<th>头像</th>
								<th>手机号</th>
								<th>用户名</th>
								<th>总接单数</th>
								<!-- <th>日均接单</th> -->
								<th>评分</th>
								<th>创建时间</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
							<tr>

								<td><input type="checkbox" name="expresscheck" id="" ></td>
								<td><img src="../../images/0.jpg"></td>
								<td>15967170412</td>
								<td>lzy</td>
								<td>12</td>
								<td>1</td>
								<!-- <td>5</td> -->
								<td>2017-6-30</td>
								<td>使用中</td>
								<td><div class="layui-btn layui-btn-danger  layui-btn-small frezzid">冻结账号</div><div class="layui-btn  layui-btn-small expres_detail">详情</div></td>
							</tr>
							<tr>
								<td><input type="checkbox" name="expresscheck" id="" ></td>
								<td><img src="../../images/1.jpg"></td>
								<td>15967179986</td>
								<td>lzy</td>
								<td>12</td>
								<td>1</td>
								<!-- <td>5</td> -->
								<td>2017-6-30</td>
								<td>使用中</td>
								<td><div class="layui-btn layui-btn-danger  layui-btn-small frezzid">冻结账号</div><div class="layui-btn  layui-btn-small expres_detail">详情</div></td>
							</tr>
							<tr>
								<td><input type="checkbox" name="expresscheck" id="" ></td>
								<td><img src="../../images/xiaosong.jpg"></td>
								<td>15967170412</td>
								<td>lzy</td>
								<td>12</td>
								<td>1</td>
								<!-- <td>5</td> -->
								<td>2017-7-1</td>
								<td>使用中</td>

								<td><div class="layui-btn layui-btn-danger  layui-btn-small frezzid">冻结账号</div><div class="layui-btn  layui-btn-small expres_detail">详情</div></td>
							</tr>
						</tbody>
					</table>
					<div class="layui-btn layui-btn-danger  layui-btn-small closeall" id="frezzall">批量冻结</div>
				</div>
			</div>
			<!--底部导航-->
			<div class="layui-footer footer footer-demo" id="admin-footer"></div>
			<!--JS模块-->
			<script type="text/javascript" src="../../layui/layui.js"></script>
			<script src="../../js/jquery-1.12.3.min.js"></script>
			<script src="../../js/index.js"></script>
			<script type="text/javascript" src="../../js/jquery.cookie.js"></script>
			<!-- DataTables JavaScript -->
			<script src="../../datatables/media/js/jquery.dataTables.min.js"></script>
			<script type="text/javascript">
			var data = {
				"code": 200,
				"courierVos": [{
					"courierId": 123123,
					"username": 15967170412,
					"headPortraitUrl": "../../images/find_1.png",
					"nickname": "快递员2号",
					"sumOrder": 325,
					"score": 91,
					"createTime": "2017-7-14",
					"userCourierState": 1
				}, {
					"courierId": 123456,
					"username": 15967170411,
					"headPortraitUrl": "../../images/0.jpg",
					"nickname": "快递员1号",
					"sumOrder": 325,
					"score": 91,
					"createTime": "2017-7-14",
					"userCourierState": 1
				}, {
					"courierId": 3456,
					"username": 15967170422,
					"headPortraitUrl": "../../images/0.jpg",
					"nickname": "快递员3号",
					"sumOrder": 325,
					"score": 91,
					"createTime": "2017-7-1",

					"userCourierState": 0
				}]
			}


			$(function() {
				$("#express").addClass('layui-this'); //对应订单管理的背景色
				$('#expressTable').DataTable({
					responsive: true,
					ordering: false,
					searching: true,
					"bLengthChange": false,
					"bRetrieve": true,
					"bFilter": true //过滤功能
				});
				expressSelectChange(1)
				adminCookie()
				alert(231)
			})

			function express_Detail(courierId) {
				window.location.href = "expressdetail.html?courierId=" + courierId;
			}

			$(document).on('click', 'tr td:not(:first)', function() {
				if ($(this).siblings().first().children().is(':checked') == false) {
					$(this).siblings().first().children().prop("checked", true);
				} else {
					$(this).siblings().first().children().prop("checked", false);
				}
			})


			$(document).on('click', '.frezzid', function() {
				k = $(this).parents("tr").index() + 1;
				var courierId = this.id
				var expressNickname = $(this).parents("tr").children('td:nth-child(4)').text()
				layui.use('layer', function() {
					var layer = layui.layer;
					layer.confirm('是否要冻结快递员：' + expressNickname + "?", {
						icon: 2,
						title: '提示'
					}, function(index) {
						/*$.ajax({
							type: "DELETE",
							url: "/randomdelivery/AdminController/closeCourier/" + courierId,
							async: true,
							dataType: "json",
							contentType: "application/json",
							success: function(data) {*/
								if (data.code == 200) {
									$("table#expressTable").find("tr:eq(" + k + ")").children('td:nth-child(8)').text("已关闭").css('color', 'red');
									$("table#expressTable").find("tr:eq(" + k + ")").children('td:nth-child(9)').children('.frezzid').text("激活账号").attr('class', 'layui-btn layui-btn-normal  layui-btn-small wakeup');
									$("input[type='checkbox']:checked").prop('checked', false)
									layer.close(index);
								}

							/*},
							Error: function() {
								alert("服务器出错");
							}
						})*/
					})

				});
			});



			$(document).on('click', '.wakeup', function() {
				k = $(this).parents("tr").index() + 1;
				var expressNickname = $(this).parents("tr").children('td:nth-child(4)').text()
				var courierId = this.id;
				layui.use('layer', function() {
					var layer = layui.layer;
					layer.confirm('是否要激活快递员：' + expressNickname + "?", {
						icon: 1,
						title: '提示'
					}, function(index) {
						/*$.ajax({
							type: "get",
							url: "/randomdelivery/AdminController/openCourier/" + courierId,
							data: {},
							async: true,
							dataType: "json",
							contentType: "application/json",
							success: function(data) {*/
								if (data.code == 200) {
									$("table#expressTable").find("tr:eq(" + k + ")").children('td:nth-child(8)').text("使用中").css('color', 'black');
									$("table#expressTable").find("tr:eq(" + k + ")").children('td:nth-child(9)').children('.wakeup').text("冻结账号").attr('class', 'layui-btn layui-btn-danger  layui-btn-small frezzid');
									$("input[type='checkbox']:checked").prop('checked', false)
									layer.close(index);
								}
							/*},
							Error: function() {
								alert("服务器出错");
							}
						});*/

					})
				});

			})



			$("#frezzall").on('click', function() {
				if ($("input[name='expresscheck']:checked").length == 0) {
					layer.msg("请选择快递员")
				} else {
					layui.use('layer', function() {
						var layer = layui.layer;
						layer.confirm('是否要冻结选中快递员？', {
							icon: 2,
							title: '提示'
						}, function(index) {
							$("input[name='expresscheck']:checked").each(function() { // 遍历选中的checkbox
								var element = this;
								if (!isNaN(element.id)) {
									/*$.ajax({
										type: "DELETE",
										url: "/randomdelivery/AdminController/closeCourier/" + element.id,
										async: true,
										dataType: "json",
										contentType: "application/json",
										success: function(data) {*/
											if (data.code == 200) {
												$(element).parents("tr").children('td:nth-child(8)').text("已关闭").css('color', 'red')
												$(element).parents("tr").children('td:nth-child(9)').children('.frezzid').text("激活账号").attr('class', 'layui-btn layui-btn-normal  layui-btn-small wakeup');
											}
										/*},
										Error: function() {
											alert("服务器出错");
										}
									});*/
								}
							});
							$("input[type='checkbox']:checked").prop('checked', false)
							layer.close(index);
						});
					})
				}
			});


			$("#expressSequence").bind("change", function() {
				expressSelectChange($(this).val())
			})

			function expressSelectChange(v) {
				/*$.ajax({
					type: "get",
					url: "/randomdelivery/AdminController/couriers/pageCount/1/pageSize/10",
					data: {
						"sequence": v,
					},
					async: true,

					dataType: "json",
					contentType: "application/json",
					success: function(data) {*/
						expressdata(data);
					/*},
					Error: function() {
						alert("服务器出错");
					}
				})*/
			}
			Date.prototype.Format = function(fmt) { //author: meizz 
				var o = {
					"M+": this.getMonth() + 1, //月份 
					"d+": this.getDate(), //日 
					"h+": this.getHours(), //小时 
					"m+": this.getMinutes(), //分 
					"s+": this.getSeconds(), //秒 
					"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
					"S": this.getMilliseconds() //毫秒 
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
					if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			}


			function expressdata(data) {
				$('#expressTable').dataTable().fnClearTable(); //清除表格内
				$.each(data.courierVos, function(index, item) {
					var state = "使用中"
					var date = new Date(item.createTime).Format("yyyy-MM-dd hh:mm:ss")
					k = index + 1
					if (item.userCourierState == 0) {
						state = "已关闭"
					} else {
						state = "使用中"
					}
					$('#expressTable').dataTable().fnAddData([

						'<input type="checkbox" name="expresscheck" id="' + item.courierId + '" >',
						'<img src=' + item.headPortraitUrl + '>',
						item.username,
						item.nickname,
						item.sumOrder,
						item.score,
						date,
						state,

						'<div class="layui-btn layui-btn-danger  layui-btn-small frezzid" id="' + item.courierId + '" >冻结账号</div><div class="layui-btn  layui-btn-small expres_detail" onclick="express_Detail(' + item.courierId + ')">详情</div>'
					]);
					if (item.userCourierState == 0) {
						$("table#expressTable").find("tr:eq(" + k + ")").children('td:nth-child(9)').children('.frezzid').text("激活账号").attr('class', 'layui-btn layui-btn-normal  layui-btn-small wakeup').attr("id", item.courierId);
						$("table#expressTable").find("tr:eq(" + k + ")").children('td:nth-child(8)').css('color', 'red');
					}
				})
			}
			</script>
			


		</script>

	</div>
</body>
</html>